/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tempo.java
 *
 * Created on 20/10/2011, 15:02:13
 */

package br.com.fatecpg.tp1.formularios;

import javax.swing.JOptionPane;

/**
 *
 * @author Fatec
 */
public class Tempo extends javax.swing.JInternalFrame {
    
    public double getConverter(double unidade) {
        if (cbConverter.getSelectedItem().equals("Anos")) {
            unidade /= 365;
        } else if (cbConverter.getSelectedItem().equals("Meses")) {
            unidade /= 30;
        } else if (cbConverter.getSelectedItem().equals("Semanas")) {
            unidade /= 7;
        } else if (cbConverter.getSelectedItem().equals("Horas")) {
            unidade *= 24;
        } else if (cbConverter.getSelectedItem().equals("Minutos")) {
            unidade *= 1440;
        } else {
            unidade *= 86400;
        }

        return unidade;
    }

    /** Creates new form Tempo */
    public Tempo() {
        initComponents();
        
        
       
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbTitulo = new javax.swing.JLabel();
        lbEm = new javax.swing.JLabel();
        tfDias = new javax.swing.JTextField();
        cbConverter = new javax.swing.JComboBox();
        lbDias = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lbResultado = new javax.swing.JLabel();
        tfResultado = new javax.swing.JTextField();

        setTitle("TEMPO");

        lbTitulo.setText("Quero Converter");

        lbEm.setText("em:");

        tfDias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfDiasActionPerformed(evt);
            }
        });

        cbConverter.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Anos", "Meses", "Semanas", "Horas", "Minutos", "Segundos" }));

        lbDias.setText("Dias:");

        jButton1.setText("Converte");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lbResultado.setText("Resultado:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbDias)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfDias, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbEm)
                        .addGap(18, 18, 18)
                        .addComponent(cbConverter, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jButton1))
                    .addComponent(lbTitulo)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbResultado)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(61, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(lbTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDias)
                    .addComponent(tfDias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbEm)
                    .addComponent(cbConverter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbResultado)
                    .addComponent(tfResultado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(166, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfDiasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDiasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfDiasActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      
        double unidade;
        unidade = Double.valueOf(tfDias.getText()).doubleValue();
        tfResultado.setText(String.valueOf(getConverter(unidade)));

    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbConverter;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lbDias;
    private javax.swing.JLabel lbEm;
    private javax.swing.JLabel lbResultado;
    private javax.swing.JLabel lbTitulo;
    private javax.swing.JTextField tfDias;
    private javax.swing.JTextField tfResultado;
    // End of variables declaration//GEN-END:variables

}
